/*
*    Phantom Test Driver v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/*
 * SuitePanelBase.java
 *
 * Created on December 5, 2005, 10:01 PM
 */

package ptd_suite_objects;

import ptd.PTDMain;

/**
 *
 * @author  John
 */
public class SuitePanelBase extends javax.swing.JPanel {
    
    SuiteBase myBase;
    
    // -- SUITE MODIFIED --
    // Panels should not be tracking data modification
    //private boolean bModified;
    
    //public void setModified(boolean bNew){
    //    bModified = bNew;
    //}
    
    //public boolean getModified(){
    //    boolean bRet = bModified;
    //    bModified = false;
    //    return bRet;
        //return bModified;
    //}
    
    /** Creates new form SuitePanelBase */
    public SuitePanelBase() {
        initComponents();
        NameLabel.setText("Name: ");
        DescriptionLabel.setText("Description: ");
        PreProcessorLabel.setText("Preprocess: ");
        PostProcessorLabel.setText("Postprocess: ");
        PreProcessBrowseButton.setText("...");
        PostProcessBrowseButton.setText("...");
    }
    
    public void clearFields(){
        DescriptionText.setText("");
        NameText.setText("");
        PreProcessorText.setText("");
        PreProcessorText.setText("");
    }
    
    public SuiteBase getFields(){
        if(myBase == null){
            return null;
        }
        SuiteBase oldBase = new SuiteBase(myBase);
        myBase.myName = NameText.getText();
        myBase.myDescription = DescriptionText.getText();
        myBase.myPostprocessor = PostProcessorText.getText();
        myBase.myPreprocessor = PreProcessorText.getText();
        
        
        if(myBase.isEqualTo(oldBase)){
        }else{
            myBase.setModified();
        }
        // -- SUITE MODIFIED --
        // setModified(true);
        return myBase;
    }
    
    public SuiteBase getNewData(){
        myBase = new SuiteBase();
        // Check for correct name
        // -- SUITE MODIFIED --
        //setModified(true);
        return getFields();
    }
    
    public SuiteBase getData(){
        return myBase;
    }

    
    public void setFields(SuiteBase In){
        // -- SUITE MODIFIED --
        //setModified(false);
        myBase = In;
        NameText.setText(myBase.myName);
        DescriptionText.setText(myBase.myDescription);
        PreProcessorText.setText(myBase.myPreprocessor);
        PostProcessorText.setText(myBase.myPostprocessor);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        NameText = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        DescriptionText = new javax.swing.JTextPane();
        NameLabel = new javax.swing.JLabel();
        DescriptionLabel = new javax.swing.JLabel();
        PreProcessorLabel = new javax.swing.JLabel();
        PreProcessorText = new javax.swing.JTextField();
        PostProcessorLabel = new javax.swing.JLabel();
        PostProcessorText = new javax.swing.JTextField();
        PreProcessBrowseButton = new javax.swing.JButton();
        PostProcessBrowseButton = new javax.swing.JButton();

        setLayout(new java.awt.GridBagLayout());

        NameText.setColumns(10);
        NameText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NameTextActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 2;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        add(NameText, gridBagConstraints);

        jScrollPane1.setPreferredSize(new java.awt.Dimension(2, 60));
        jScrollPane1.setViewportView(DescriptionText);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(jScrollPane1, gridBagConstraints);

        NameLabel.setOpaque(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        add(NameLabel, gridBagConstraints);

        DescriptionLabel.setOpaque(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 2;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        add(DescriptionLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(PreProcessorLabel, gridBagConstraints);

        PreProcessorText.setColumns(10);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 2;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        add(PreProcessorText, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(PostProcessorLabel, gridBagConstraints);

        PostProcessorText.setColumns(10);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 2;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        add(PostProcessorText, gridBagConstraints);

        PreProcessBrowseButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        PreProcessBrowseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PreProcessBrowseButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        add(PreProcessBrowseButton, gridBagConstraints);

        PostProcessBrowseButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        PostProcessBrowseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PostProcessBrowseButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        add(PostProcessBrowseButton, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void PostProcessBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PostProcessBrowseButtonActionPerformed
        String sFile = PTDMain.openPSCFile();
        if(sFile != ""){
            PostProcessorText.setText(sFile);
        }
    }//GEN-LAST:event_PostProcessBrowseButtonActionPerformed

    private void PreProcessBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PreProcessBrowseButtonActionPerformed
        String sFile = PTDMain.openPSCFile();
        if(sFile != ""){
            PreProcessorText.setText(sFile);
        }
    }//GEN-LAST:event_PreProcessBrowseButtonActionPerformed

    private void NameTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NameTextActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_NameTextActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JLabel DescriptionLabel;
    protected javax.swing.JTextPane DescriptionText;
    protected javax.swing.JLabel NameLabel;
    protected javax.swing.JTextField NameText;
    private javax.swing.JButton PostProcessBrowseButton;
    private javax.swing.JLabel PostProcessorLabel;
    protected javax.swing.JTextField PostProcessorText;
    private javax.swing.JButton PreProcessBrowseButton;
    private javax.swing.JLabel PreProcessorLabel;
    protected javax.swing.JTextField PreProcessorText;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    
}
